package com.iwop.moto.controller;

import com.iwop.moto.comm.ErrCode;
import com.iwop.moto.model.ResultModel;
import com.iwop.moto.model.SuperRecordModel;
import com.iwop.moto.service.DistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author  liuwb by 2016-08-31
 * @explain 全国统一四级分区 [ 省、市、区/县、镇/乡/街道 ]
 * @ver     Create by 1.0
 */
@Controller
public class DistrictController extends  BaseController {

    @Autowired
    private DistrictService districeService;

    /**
     * @author:  liuwb by 2016-08-31
     * @explain: 根据动态参数查询区域信息
     * @param:  param_id    主键 (选填)
     * @param:  param_level 区域等级(选填)
     * @param:  param_upid  上级id(选填)
     */
    @RequestMapping("/api/district/by/param")
    @ResponseBody
    public ResultModel ApiDistrictByParam(){
        SuperRecordModel SRModel = this.getSRModel();
        try {
            List<SuperRecordModel> lists = districeService.findDistrictByParam(SRModel);
            if(lists==null ){
                return getErr(ErrCode.ERROR_NOCOUNT);
            } else {
                return getSucceed(lists);
            }
        }catch (Exception e){
            e.printStackTrace();
            return getErr(ErrCode.ERROR_SYSTEM);
        }
    }

}
